package cn.wolfcode.shop.cloud.mapper;

import cn.wolfcode.shop.cloud.domain.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface GoodsMapper {
    @Select("select * from t_goods where id = #{id}")
    Goods get(Long id);


    @SelectProvider(type = GoodQuery.class, method = "queryGoods")
    List<Goods> queryGoods(@Param("ids") ArrayList ids);


    class GoodQuery {
        public String queryGoods(@Param("ids") ArrayList ids) {
            StringBuilder sb = new StringBuilder(100);
            sb.append("select * from t_goods where id in (");
            if (ids != null && ids.size() > 0) {
                for (int i = 0; i < ids.size(); i++) {
                    if (i != 0) {
                        sb.append(",");
                    }
                    sb.append(ids.get(i));
                }
                sb.append(" ) ");
            }
            return sb.toString();
        }
    }
}